package lowijs.XfireClient.packet;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import lowijs.XfDroid.FriendDBAdapter;

public class FriendStatusPacket extends Packet {
	public static String[] invoke(byte[] data) {
		int numSids = fromLowHigh(data[12], data[13]);
		long[] friends = new long[numSids];
		int pos = 14;

		ByteBuffer buffer = ByteBuffer.wrap(data);
		buffer.order(ByteOrder.LITTLE_ENDIAN);

		for (int i = 0; i < numSids; i++) {
			friends[i] = buffer.getInt(pos);
			pos += 4;
		}

		pos += 8; // jump to the sids

		byte[][] sids = new byte[numSids][16];
		for (int i = 0; i < numSids; i++) {
			System.arraycopy(data, pos, sids[i], 0, 16);
			pos += 16;
		}

		FriendDBAdapter db = FriendDBAdapter.getInstance(null);
		return db.status(friends, sids);
	}
}
